package com.easysoft.framework.article.service;
import com.easysoft.commons.utils.DateTimeUtils;
import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.article.mapper.SysSingleMapperExtd;
import com.easysoft.framework.article.model.*;
import com.easysoft.framework.beans.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by try on 2017/7/31.
 */
@Service("service.SysSingleService")
public class SysSingleService {

    @Autowired
    @Qualifier("mapper.SysSingleMapperExtd")
    private SysSingleMapperExtd sysSingleMapperExtd;

    /**
     *  获取单页列表
     *
     * @param page
     * @param query
     * @return
     */
    @DataSource(DataSource.SLAVE)
    public List<SysSingleView> selectSysSingleListByPage(Page page, SysSingleQuery query){

        int maxRow = sysSingleMapperExtd.selectSysSingleListCount(query);
        page.setMaxRow(maxRow);

        if (maxRow == 0) {
            return new ArrayList<SysSingleView>();
        }
        return sysSingleMapperExtd.selectSysSingleListByPage(page,query);
    }

    /**
     * 删除文章列表
     * @param id
     * @return
     */
    @DataSource(DataSource.MASTER)
    public int deleteByPrimaryKey(String id){
        return sysSingleMapperExtd.deleteByPrimaryKey(id);
    }

    /**
     * 查询单页
     * @param id
     * @return
     */
    @DataSource(DataSource.SLAVE)
    public SysSingle selectByPrimaryKey(String id){
        return sysSingleMapperExtd.selectByPrimaryKey(id);
    }


    /**
     * 更新单页内容
     * @param sysSingle
     * @return
     */
    @DataSource(DataSource.MASTER)
    public int updateBySelective(SysSingle sysSingle){
        System.out.println("wwwwww");
        System.out.println("wwwwww");
        return sysSingleMapperExtd.updateByPrimaryKeySelective(sysSingle);
    }

    /**
     * 新增单页
     * @param sysSingle
     * @return
     */
    @DataSource(DataSource.MASTER)
    public int addByPrimaryKeyWithBLOBs(SysSingle sysSingle){

        sysSingle.setId(UUIDUtils.getUUID());
        sysSingle.setCreateTime(DateTimeUtils.getCurrentDate());

        return sysSingleMapperExtd.insertSelective(sysSingle);
    }

}
